<template>
    <div class="dialog">
        <a-modal
            v-drag-modal
            class="opinionDialog"
            title="批量推荐"
            :visible="visible"
            @cancel="handleCancel"
            :maskClosable="false"
        >
            <template slot="footer">
                <a-button type="primary" html-type="submit" @click="onSubmit">确定</a-button>
            </template>
            <div class="dialogCont">
                <a-form-model
                    ref="ruleForm"
                    :model="queryParam"
                    :rules="ruleValidate"
                    :label-col="labelCol"
                    :wrapper-col="wrapperCol"
                >
                    <a-form-model-item ref="tjyj_sftj" label="是否推荐" prop="tjyj_sftj">
                        <a-radio-group name="radioGroup" v-model="queryParam.tjyj_sftj">
                            <a-radio value="203">同意推荐</a-radio>
                            <a-radio value="202">不同意推荐</a-radio>
                            <a-radio value="201">退回修改</a-radio>
                        </a-radio-group>
                    </a-form-model-item>
                    <a-form-model-item v-if="queryParam.tjyj_sftj != 203" ref="tjyj_yj" label="推荐意见" prop="tjyj_yj">
                        <a-input placeholder="请输入推荐意见" v-model="queryParam.tjyj_yj" type="textarea" :auto-size="{ minRows: 5}"/>
                    </a-form-model-item>
                </a-form-model>
            </div>
        </a-modal>
    </div>
</template>
<script>
import { cxjCgCxjglCxjpltjAddTjdw } from '@/api/api'
export default {
    props: ['showFlag', 'cxjIds'],
    data() {
        return {
            visible: false,
            labelCol: { span: 4 },
            wrapperCol: { span: 14 },
            queryParam: {
                tjyj_sftj: '203',
                tjyj_yj: ''
            },
            ruleValidate: {
                tjyj_sftj: [{ required: true, message: '请选择是否推荐', trigger: 'change' }],
                tjyj_yj: [{ required: true, message: '请输入推荐意见', trigger: 'blur' }]
            },
        }
    },
    watch: {
        showFlag(next, prev) {
            if (next != prev) {
                var self = this
                self.visible = !self.visible
            }
        }
    },
    methods: {
        onSubmit() {
            let self = this
            self.$refs.ruleForm.validate((valid, value) => {
                if (valid) {
                    console.log('校验通过', self.queryParam.opinion)
                    cxjCgCxjglCxjpltjAddTjdw({
                        cxjIds: self.cxjIds,
                        tjyj_sftj: self.queryParam.tjyj_sftj,
                        tjyj_yj: self.queryParam.tjyj_yj
                    }).then(res => {
                        if (res.code == 200) {
                            self.$message.success(res.message);
                            self.handleCancel()
                            self.$emit('callback');
                        } else {
                            this.$message.warning(res.message);
                        }
                    })
                } else {
                    return false
                }
            })
        },
        handleCancel() {
            this.$refs.ruleForm.resetFields()
            this.visible = false
        }
    }
}
</script>
<style lang="less" scoped>

</style>
